use crate::vm::{addr::paddr::Paddr, pgtable::page::PAGE_MASK};

use super::prot::{KernelPageProt, UserPageProt};

pub struct PTEntry(u64);

impl PTEntry {
    pub fn new() -> Self {
        Self(0)
    }

    pub fn map_user_sect(&mut self, phys: Paddr, prot: UserPageProt) {
        assert!((phys.to_value() & !PAGE_MASK) == 0);
        let new_pte = prot.bits() | phys.to_value() as u64;
        self.0 = new_pte;
    }

    pub fn map_kern_sect(&mut self, phys: Paddr, prot: KernelPageProt) {
        assert!((phys.to_value() & !PAGE_MASK) == 0);
        let new_pte = prot.bits() | phys.to_value() as u64;
        self.0 = new_pte;
    }
}

impl Default for PTEntry {
    fn default() -> Self {
        Self::new()
    }
}
